import { defineStore } from "pinia";
import { Add_speak, get_list, put_one, delete_one } from "@/apis/SpeakApi"
import { type Speak, type Upspeak } from "@/types/Speak";
import { ElMessage } from "element-plus";
const SpeakStore = defineStore("speak", () => {
    const speak_add = async (data: Speak) => {
        const result: any = await Add_speak(data)
        if (result.code == 200) {
            ElMessage({
                type: "success",
                message: "添加成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "添加失败"
            })
        }
    }
    const Get_list_speak = async (id: number) => {
        const result: any = await get_list(id)
        if (result.code == 200) {
            console.log(result)

            return {
                data: result.data,
                count: result.count
            }
        }
    }
    //修改
    const one_put = async (data: Upspeak) => {
        const result: any = await put_one(data)
        if (result.code == 200) {
            ElMessage({
                type: "success",
                message: "修改成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "修改失败"
            })
        }
    }
    //删除
    const one_delete = async (id: string) => {
        const result: any = await delete_one(id)
        if (result.code == 200) {
            ElMessage({
                type: "success",
                message: "删除成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "删除失败"
            })

        }
    }
    return {
        speak_add,
        Get_list_speak,
        one_put,
        one_delete
    }
})

export default SpeakStore